﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using ScytaleDecrypt.Model.Interfaces;

namespace ScytaleDecrypt.Model
{
    public class Message : IDecryptable {
        private String originalMessage;
   
        public string OriginalMessage {
            get {
                return originalMessage;
            }
            set {
                if (value.Length != 0) {
                    originalMessage = value;
                    MessageLength = value.Length;
                }
            }
        }

        public int MessageLength { get; set; }

        private List<string> DecryptedMessages { get; set; }

        public Message() {
            OriginalMessage = "";
            MessageLength = 0;
            DecryptedMessages = new List<string>();
        }

        public List<String> Decrypt()
        {
            DecryptedMessages.Clear();
            for (int currentChunksize = 2; currentChunksize <= MessageLength; currentChunksize++)
            {
                if (currentChunksize == 6) {
                    string bla = "blabl";
                }
                ProcessedMessage processedMessage = new ProcessedMessage(OriginalMessage, currentChunksize);
                List<String> decryptedMessage = processedMessage.Decrypt();
                if (decryptedMessage.Count > 0) {
                    DecryptedMessages.AddRange(decryptedMessage);
                }
            }
            if (DecryptedMessages.Count > 0)
                return DecryptedMessages;
            return null; 
        }
    }
}
